const fs = require("fs");

const PASSWORD = '';
const DATA_URL = './data.txt';

function encript(pass, data) {
    const PASS_BYTES = pass.split('').map(char => char.charCodeAt(0));
    const DATA_BYTES = data.split('').map(char => char.charCodeAt(0));
    
    let encriptDataBytes = DATA_BYTES.map(dataByte => {
        let encriptByte = dataByte;
        
        PASS_BYTES.forEach(passByte => {
            encriptByte ^= passByte;
        });
        
        return encriptByte;
    });

    return encriptDataBytes.reduce((string, byte) => {
        return string + String.fromCharCode(byte);
    }, '');
}

let data = fs.readFileSync(DATA_URL, 'utf-8');
let encripted = encript(PASSWORD, data);

fs.writeFileSync(DATA_URL, encripted);
